package com.ody.util.code.generator;

import com.google.common.collect.Lists;
import com.odianyun.util.excel.ExcelFileType;
import com.odianyun.util.excel.Excels;
import com.odianyun.util.excel.exporter.ExcelExportConfig;

import java.io.FileOutputStream;

public class ExcelFileCodeGenerator extends FileCodeGenerator {
    
    @Override
    protected void doWriteFile(String content, String targetDir, String file) throws Exception {
        String[] lines = content.split("[\r\n]");
        ExcelExportConfig cfg = new ExcelExportConfig();
        for (String line : lines) {
            if (line.trim().length() > 1) {
                String[] kv = line.trim().split("[=:]");
                cfg.mapColName(kv[0], kv[1]);
            }
        }
    
        try (FileOutputStream fos = new FileOutputStream(file)) {
            Excels.newExcelExporter(ExcelFileType.XLSX).setSheetData(Lists.newArrayList(), cfg).export(fos);
        }
    }
}
